package com.bj58.ecdata.mailreport.service.impl;

import java.util.List;

import com.bj58.ecdata.mailreport.db.CommonDao;
import com.bj58.ecdata.mailreport.db.DBConfig;
import com.bj58.ecdata.mailreport.model.IEMainSrc;
import com.bj58.ecdata.mailreport.model.Paginate;
import com.bj58.ecdata.mailreport.service.AbstractBaseService;

public class IEMainSrcService extends AbstractBaseService<IEMainSrc>{
	private CommonDao comDao = new CommonDao();
	
	public Paginate<IEMainSrc> getPagList(String conString,int pageIndex,int pageNum) throws Exception{
		
		String countSQL = "select count(1) from (select 1 from ie_main_src where 1=1 "+conString+" group by id)m" ;
		int count = comDao.countAll(countSQL, DBConfig.db_manage.getIntType());
		String searchSql = "select * from ie_main_src where 1=1 "+conString+" group by id  order by creatTime desc" ;
		if(pageIndex > 0){
			searchSql +=" limit "+(pageIndex-1)*pageNum+","+pageNum;//limit分页
		}else{
			searchSql +=" limit 0,"+pageNum;
		}
		
		List<IEMainSrc>  rsList = comDao.getAllColsByVo(searchSql, IEMainSrc.class, DBConfig.db_manage.getIntType());
		Paginate<IEMainSrc> pList = new Paginate<IEMainSrc>(count,pageIndex,pageNum,rsList);
		return pList;
		
	}

	public List<IEMainSrc> getSrcTableById(int mainID) throws Exception {
		String searchSql = "select * from ie_main_src where id="+mainID+" and srcTable!='' and srcTable is not null group by dbId,srcTable" ;
		List<IEMainSrc>  rsList = comDao.getAllColsByVo(searchSql, IEMainSrc.class, DBConfig.db_manage.getIntType());
		return rsList;
	}
}
